﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Playables;
using UnityEngine.Rendering;

namespace Projectsurviva
{
    /// <summary>
    /// model 层
    /// </summary>
    public class CoinUpdataItem
    {
        public EasyEvent OnChanged=new EasyEvent();
        public bool Upgradefinish { get; set; } = false;
        public string key { get; set; }
        public string Description { get; set; }
        public int price { get; set; }

        public void Upgrade() 
        {
            mOnupgrade?.Invoke(this);
            Upgradefinish = true;
            OnChanged.Trigger();

            CoinupdataSystem.OnCoinUpgradeSystemChanged.Trigger();
        }
        private Action<CoinUpdataItem> mOnupgrade; 

        private Func<CoinUpdataItem,bool> mCondition;
        public bool ConditionCheck()
        {
            if (mCondition == null)
            {
                return !Upgradefinish;
            }
            else
            {
                return !Upgradefinish && mCondition.Invoke(this);
            }
        }
        public CoinUpdataItem withkey(string Key)
        {
            key = Key;
            return this;
        }
        public CoinUpdataItem withdescription(string description)
        {
            Description = description;
            return this;
        }
        public CoinUpdataItem withAction(Action<CoinUpdataItem> Onupgrade)
        {
            mOnupgrade = Onupgrade;
            return this;
        }
        public CoinUpdataItem withPrice(int price)
        {
            this.price = price;
            return this;
        }
        public CoinUpdataItem WithCondition(Func<CoinUpdataItem, bool> condition)
        {
            mCondition = condition;
            return this;
        }
    }
}
